package wallet

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/wallet/pb"
	"navi-mumbai/common/ctxdata"
	"navi-mumbai/common/key/walletkey"
	"navi-mumbai/common/xerr"

	"navi-mumbai/app/api/business/internal/svc"
	"navi-mumbai/app/api/business/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DepositForTestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDepositForTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DepositForTestLogic {
	return &DepositForTestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DepositForTestLogic) DepositForTest(req *types.DepositForTestReq) (resp *types.DepositForTestResp, err error) {
	uid := ctxdata.GetUidFromCtx(l.ctx)
	if uid != req.Uid {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.AuthFail, "no privilege")
	}

	var in pb.DepositDirectReq
	in.Uid = req.Uid
	in.MoneyType = req.MoneyType
	in.MoneyAmount = req.MoneyAmount
	in.CurrencyAmount = req.CurrencyAmount
	in.CurrencyType = req.CurrencyType
	in.PayChannelId = walletkey.PayChannelIdTest
	var rsp *pb.DepositDirectResp
	rsp, err = l.svcCtx.WalletSysRpc.DepositDirect(l.ctx, &in)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, err
	}
	resp = &types.DepositForTestResp{MoneyType: rsp.MoneyType, Balance: rsp.Balance}
	return
}
